$(function(){
    const url = window.location.href
    const eform_id = url.match(/\/(\d+)$/)[1];
    const csrf = $('input[name="csrfmiddlewaretoken"]').val()

    let getAllIMTE = () => {
          
      return axios.get(get_all_imte_url,
          {
              params:{
                  eform_id
              }
          },
          {
              headers: {
                  'X-CSRFToken': csrf,
              }
          })
  }


  let appendToUI = function (imte_no,due_date) {
    $('#imte-tbody').append(
        `
        <tr id="tr-${imte_no}">
        <td>
        ${imte_no}
        </td>
        <td>
        ${due_date}
        </td>
        <td class="text-center">
            <button type="button" class="btn btn-sm imte-delete px-2 py-2  btn-primary" data-imte="${imte_no}"><i class="fa fa-times" aria-hidden="true"></i></button>
        </td>
        </tr>
        `
    )
}

  dataJson.display="form"
  Formio.icons = 'fontawesome';
  Formio.createForm(document.getElementById('formio'), 
      
      dataJson,{readOnly:true}
  ).then(function(form) {
      form.submission  = {
        data:data
      }
  }).then(function(){
    getAllIMTE().then(res=>{
      res.data.data.forEach(v=>{
          appendToUI(v.imte_no,v.due_date)
      })
      window.print()
  })

  })
    // window.onfocus=function(){ window.close();}
  });

